/**
 * @file ConfigManager.hpp
 *
 * @author Alejandro Dario Simi
 * @url http://www.daemonraco.com
 * @date 2011-12-03
 */

#ifndef __CONFIGMANAGER_HPP__
#define __CONFIGMANAGER_HPP__

#include <string>
#include <vector>
#include <map>
using namespace std;

#include <defines.h>

class ConfigManager {
	public:
		typedef struct {
			bool	active;
			string	name;
			string	command;
			string	icon;
			string	description;
		} __MacroButtonInfo;
		typedef __MacroButtonInfo MacroButtonInfo[XADOS_CONF_MBUTTON_COUNT];
		typedef struct {
			bool	active;
			string	name;
			string	flag;
			string	description;
		} __CheckBoxesInfo;
		typedef __CheckBoxesInfo CheckBoxesInfo[XADOS_CONF_CBOXES_COUNT];
		typedef struct {
				string	description;
				string	keyword;
				string	name;
		} MainProgram;
		typedef struct {
				bool	active;
				string	directory;
				string	keyword;
		} BrowserInfo;


	protected:
		string			_config;
		string			_configPath;
		string			_script;
		bool			_isLoaded;
		MacroButtonInfo		_macroButtons;
		CheckBoxesInfo		_checkBoxes;
		MainProgram		_program;
		BrowserInfo		_browser;
		map<string,string>	_keywords;
		bool			_startSmall;
		string			_logo;
		string			_checkBoxesKeyword;
		bool			_hasCheckBoxes;

	public:
		ConfigManager(string config);
		virtual ~ConfigManager();

	public:
		/**
		 * @return Returns the browser frame configuration.
		 */
		virtual const BrowserInfo &browser() const;
		virtual const CheckBoxesInfo &checkBoxes() const;
		virtual string checkBoxesKeyword() const;
		virtual string config() const;
		virtual bool hasCheckBoxes() const;
		/**
		 * @return Returns true when the configuration was loaded.
		 */
		virtual bool isLoaded();
		/**
		 * @return Returns a map of keywords and their replacements.
		 */
		virtual const map<string, string> &keywords() const;
		/**
		 * @return Returns the full path of logotype to use. If there's
		 * none configured, it returns an empty string.
		 */
		virtual string logo() const;
		virtual const MacroButtonInfo &macroButtons() const;
		virtual const MainProgram &program() const;
		virtual string replaceKeywords(const string &command) const;
		/**
		 * Sets a keyword replacement.
		 *
		 * @param keyword Word to seek.
		 * @param replacement Value to ve used as replacement for a
		 * keyword.
		 * @return Returns true when keyword already exists and it's
		 * replaced. Otherwise, returns false.
		 */
		virtual bool setKeyword(const string &keyword, const string &replacement);
		/**
		 * @return Returns true when the Xados' excecutor must be started
		 * in the compact version.
		 */
		virtual bool startSmall() const;

	protected:
		virtual bool addCheckBox(const vector<string> &conf);
		virtual bool addMacroButton(const vector<string> &conf);
		virtual int expandConfigLine(const string line, vector<string> &lines) const;
		virtual bool load();
		virtual bool loadConfigLine(const vector<string> &conf);
		virtual string noCommentsConfigLine(const string line) const;
		virtual bool setBrowser(const vector<string> &conf);
		virtual bool setCheckBoxes(const vector<string> &conf);
		virtual bool setLogo(const vector<string> &conf);
		virtual bool setMainProgram(const vector<string> &conf);
};

#endif /* __CONFIGMANAGER_HPP__ */
